﻿namespace DesignModeConsole.结构型.外观模式;

/// <summary>
/// 普通的写法
/// </summary>
public class CommonSample
{
    public void Main()
    {
        const int amout = 1000;

        var customer = new Customer("张三");

        var bank = new Bank();
        var loan = new Loan();
        var credit = new Credit();

        var eligible = true;
        if (!bank.HasSufficientSavings(customer, amout))
        {
            eligible = false;
        }
        else if (!loan.HasNoBadLoans(customer))
        {
            eligible = false;
        }
        else if (!credit.HasGoodCredit(customer))
        {
            eligible = false;
        }

        var result = eligible ? "满足" : "不满足";
        Console.WriteLine($"顾客{customer.Name} {result}贷款要求");
    }
}

/// <summary>
/// 顾客类
/// </summary>
public class Customer
{
    public Customer(string name)
    {
        Name = name;
    }

    public string Name { get; set; }
}

/// <summary>
/// 银行子系统
/// </summary>
public class Bank
{
    public bool HasSufficientSavings(Customer customer, int amount)
    {
        Console.WriteLine("检查顾客" + customer.Name + "余额");
        return true;
    }
}

/// <summary>
/// 信用子系统
/// </summary>
public class Credit
{
    public bool HasGoodCredit(Customer customer)
    {
        Console.WriteLine($"检查顾客{customer.Name}信用");
        return true;
    }
}

/// <summary>
/// 贷款子系统
/// </summary>
public class Loan
{
    public bool HasNoBadLoans(Customer customer)
    {
        Console.WriteLine($"检查顾客{customer.Name}是否有不良的贷款");
        return true;
    }
}